package com.credit.jumu.playcard.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.credit.jumu.playcard.R;
import com.credit.jumu.playcard.adapter.HomeListAdapter;
import com.credit.jumu.playcard.adapter.RepaymentListAdapter;
import com.credit.jumu.playcard.bean.HomeInfo;
import com.credit.jumu.playcard.bean.RepayInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jpeng on 16-11-14.
 *///账单
public class BillOneFragment extends Fragment {
	ListView billoneList;
	private List<RepayInfo> mlistInfo = new ArrayList<RepayInfo>();
	ImageView bill1_nodata, upanddown;
	TextView bill1_nodatatext;
	LinearLayout bill_one_head;
	private boolean listIsShow = false;

	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_billone, null);
		initView(view);
		return view;
	}

	private void initView(View view) {
		setInfo();
		billoneList = view.findViewById(R.id.billoneList);
		billoneList.setAdapter(new RepaymentListAdapter(mlistInfo, getActivity()));
		bill1_nodata = view.findViewById(R.id.bill1_nodata);
		bill1_nodatatext = view.findViewById(R.id.bill1_nodatatext);
		if (mlistInfo.size() == 0) {
			bill1_nodata.setVisibility(View.VISIBLE);
			bill1_nodatatext.setVisibility(View.VISIBLE);
		} else {
			bill1_nodata.setVisibility(View.GONE);
			bill1_nodatatext.setVisibility(View.GONE);
		}
		upanddown = view.findViewById(R.id.upanddown);
		bill_one_head = view.findViewById(R.id.bill_one_head);
		bill_one_head.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (listIsShow) {
					billoneList.setVisibility(View.GONE);
					upanddown.setImageResource(R.mipmap.down);
				} else {
					billoneList.setVisibility(View.VISIBLE);
					upanddown.setImageResource(R.mipmap.up);
				}
				listIsShow = !listIsShow;

			}
		});
	}

	public void setInfo() {
		mlistInfo.clear();
		int i = 0;
		while (i < 4) {
			RepayInfo information = new RepayInfo();
			information.setNoney("12561.00");
			information.setTime("2017-05-12");
			information.setType("消费");
			mlistInfo.add(information); //将新的info对象加入到信息列表中
			i++;
		}
	}
}